//
//  LZManageReviewsVideoReviewsHeaderView.m
//  laziz_Merchant
//
//  Created by xbn_iMac on 2016/12/19.
//  Copyright © 2016年 XBN. All rights reserved.
//

#import "LZManageReviewsVideoReviewsHeaderView.h"
#import "LZManageReviewsPromotionVideoListModel.h"
#import "HCSStarRatingView.h"
#import "UIImageView+WebCache.h"
#import "Masonry.h"

@interface LZManageReviewsVideoReviewsHeaderView ()
{
    CGRect myframe;
}

@property (weak, nonatomic) IBOutlet UIImageView *headImage;
@property (weak, nonatomic) IBOutlet UILabel *labTitle;
@property (weak, nonatomic) IBOutlet UILabel *labTotalPoints;
@property (weak, nonatomic) IBOutlet UIView *starBgView;
@property (weak, nonatomic) IBOutlet UILabel *labNoReviewRemind;

@property (weak, nonatomic) HCSStarRatingView *starRatingView;

@end

@implementation LZManageReviewsVideoReviewsHeaderView

-(instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        NSArray *nibs=[[NSBundle mainBundle]loadNibNamed:@"LZManageReviewsVideoReviewsHeaderView" owner:nil options:nil];
        self=[nibs objectAtIndex:0];
        self.frame = frame;
        myframe = frame;
    }
    return self;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    
    self.labTotalPoints.text = LZLocalizedString(@"review_total_points", nil);
    self.labNoReviewRemind.hidden = YES;
    self.labNoReviewRemind.text = LZLocalizedString(@"review_norating_now", nil);
    self.starBgView.backgroundColor = [UIColor clearColor];

    /*
     ==========================================Star =================================================
     */
    
    int number = 5;
    HCSStarRatingView *star = [[HCSStarRatingView alloc]initWithFrame:CGRectZero];
    star.maximumValue = number;
    star.minimumValue = 0;
    star.spacing = 2.5;
    star.allowsHalfStars = YES;
    star.accurateHalfStars = YES;
    star.tintColor = UIColorFromRGB(0xF08F4D, 1);
    star.userInteractionEnabled = NO;
    
    self.starRatingView = star;
    
    [self.starBgView addSubview:star];
    
    [star makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.starBgView);
    }];
}

- (void)setModel:(LZManageReviewsPromotionVideoListModel *)model {
    
    // 优惠视频图片
    [self.headImage sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",APIBaseImageUrl,model.videoPhoto]] placeholderImage:[UIImage imageNamed:@"lz_other_placehoiderImage"]];
    
    // 优惠视频名称
    self.labTitle.text = model.promotionTitle;
    
    BOOL isHaveReview = model.remarkCountPerson>0;
    // 星星指数
    self.starRatingView.hidden = !isHaveReview;
    self.labNoReviewRemind.hidden = isHaveReview;
    if (isHaveReview) {
        self.starRatingView.value = (CGFloat)model.remarkCountScore/model.remarkCountPerson;
    }
}


- (void)drawRect:(CGRect)rect {
    [super drawRect:rect];
    self.frame = myframe;
}



@end
